<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="108px">
      <el-form-item label="姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          size="small"
        />
      </el-form-item>
      <el-form-item label="请假类型" prop="leaveType">
          <el-select v-model="queryParams.leaveType" clearable placeholder="请选择">
            <el-option
                v-for="dict in dict.type.leave_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
                size="small">
              </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="请假天数" prop="leaveDays">
        <el-input
          v-model="queryParams.leaveDays"
          placeholder="请输入请假天数"
          size="small"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="leaveStatus">
          <el-select v-model="queryParams.leaveStatus" clearable placeholder="请选择">
            <el-option
                v-for="dict in dict.type.leave_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
                size="small">
              </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="请假时间" prop="leaveTime">
        <el-date-picker
          v-model="queryParams.leaveTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="姓名" align="center" prop="studentName" />
<!--      <el-table-column label="班级" align="center" prop="className" />-->
      <el-table-column label="请假开始时间" align="center" prop="startDate" />
      <el-table-column label="请假结束时间" align="center" prop="endDate"/>
      <el-table-column label="请假类型" align="center" prop="leaveType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.leave_type" :value="scope.row.leaveType"/>
        </template>
      </el-table-column>
      <el-table-column label="请假天数" align="center" prop="leaveDays"/>
<!--      <el-table-column label="审核人" align="center" prop="deviceName" />-->
<!--      <el-table-column label="审核时间" align="center" prop="deviceName" />-->
      <el-table-column label="审核状态" align="center" prop="leaveStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.leave_status" :value="scope.row.leaveStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >编辑</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['base:student:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生对话框 -->
    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-form-item label="姓名" prop="stuId">
            <el-select v-model="form.stuId"  placeholder="请选择" disabled>
              <el-option
                v-for="item in studentselect"
                :key="item.id"
                :label="item.label"
                :value="item.id"
                size="small">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="请假开始时间" prop="startDate">
            <el-date-picker clearable size="small"
                            v-model="form.startDate"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择开始时间"
              disabled
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="请假结束时间" prop="endDate">
            <el-date-picker clearable size="small"
                            v-model="form.endDate"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择开始时间"
                            disabled
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="请假类型" prop="leaveType">
            <el-select v-model="form.leaveType"  placeholder="请选择" disabled>
              <el-option
                v-for="dict in dict.type.leave_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
                size="small">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="请假天数" prop="leaveDays">
            <el-input type="text" v-model="form.leaveDays" disabled/>
          </el-form-item>
          <el-form-item label="请假原因" prop="reason">
            <el-input type="textarea" v-model="form.reason" disabled/>
          </el-form-item>
          <el-form-item label="审核状态" prop="leaveStatus">
            <el-select v-model="form.leaveStatus"  placeholder="请选择">
              <el-option
                v-for="dict in dict.type.leave_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
                size="small">
              </el-option>
            </el-select>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>


import { listIllstudents, updateIllstudents } from '@/api/base/ill'
import { selectStudent } from '@/api/base/student'
import { updateYdevicerecord } from '@/api/base/device'

export default {
  name: "leavercord",
  dicts:['leave_type','leave_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      total:0,
      classList:null,//班级
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentName: '',
        leaveType: null,
        leaveDays: null,
        leaveStatus: null,
        leaveTime: ''
      },
      // 显示搜索条件
      showSearch: true,
      studentList:[],
      // 表单参数
      form: {
        leaveStatus:'1'
      },
      studentselect:[],//用户下拉
      rules: {},
      leaveTypeList:[],//请假类型下拉
      leaveStatusList:[],//审核状态下拉
    };
  },
  created() {
    this.getList()
    //幼儿
    this.getStudentSelect()
  },
  methods: {
    /**幼儿下拉*/
    async getStudentSelect(){
      try {
        const data=await selectStudent()
        this.studentselect=data.rows.map(item=>{
          return {
            id:item.id,
            label:item.name
          }
        })
      }catch (e) {
        console.log(e)
      }
    },
    /**幼儿列表*/
    async getList(){
      try {
        this.loading = true;
        await listIllstudents(this.queryParams).then(res=>{
          if(res.code==200){
            this.studentList=res.rows
            this.total=res.total
          }
        })

        this.loading = false;
      }catch (e) {
        console.log(e)
      }
    },
    /***更改状态提交*/
    submitForm(){
      this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateIllstudents(this.form).then(response => {
                if(response.code==200){
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }else{
                  this.msgError(response.msg);
                }
              });
            }
          }
      })
    },
    /* 新增 */
    handleAdd(){

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /***/
    handleUpdate(row){
      this.reset();
      const id = row.id || this.ids
      this.form = Object.assign({}, this.form, row)
      this.open = true;
      this.title = "修改请假管理";
    },
    // 表单重置
    reset() {
      this.form = {
        endDate:null,
        leaveDays:null,
        leaveStatus:null,
        leaveType:null,
        reason:null,
        startDate:null,
        stuId:null,
      };
      this.resetForm("form");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-date-editor.el-input, .el-date-editor.el-input__inner{
  width: 200px;
}
::v-deep .el-select{
  width: 200px;
}
</style>
